Fix a problem with focus handling in modal popovers
authorMatthias Clasen <mclasen@redhat.com>
Fri, 11 Aug 2017 16:03:54 +0000 (12:03 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 12 Aug 2017 22:48:14 +0000 (18:48 -0400)
When the popover is dismissed, we return the focus to
where it came from. However, by using gtk_widget_grab_focus,
we were messing up the selection if that widget happens to
be an entry. Special-case GtkEntry and use
gtk_entry_grab_focus_without_selecting to avoid this issue.

gtk/gtkpopover.c

index 47603727ce46e6a97291a1a84566db2d1b5c8fed..4e7002ac2b1aa37fc3f9273e36dc9a0c97f51b0f 100644 (file)
@@ -622,7 +622,12 @@ gtk_popover_apply_modality (GtkPopover *popover,
       /* Let prev_focus_widget regain focus */
       if (priv->prev_focus_widget &&
           gtk_widget_is_drawable (priv->prev_focus_widget))
-        gtk_widget_grab_focus (priv->prev_focus_widget);
+        {
+           if (GTK_IS_ENTRY (priv->prev_focus_widget))
+             gtk_entry_grab_focus_without_selecting (GTK_ENTRY (priv->prev_focus_widget));
+           else
+             gtk_widget_grab_focus (priv->prev_focus_widget);
+        }
       else if (priv->window)
         gtk_widget_grab_focus (GTK_WIDGET (priv->window));